package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 演示AOP中JoinPoint对象的方法
 */
@Slf4j
@Aspect
@Component
public class AspectDemo3 {


    //前置通知
    @Before("@annotation(com.itheima.aop.Log)") //增强方法上带有@Log注解的
    public void before(JoinPoint jp) {
        //获取类名称
        String className = jp.getTarget().getClass().getName();
        //获取方法名称
        MethodSignature signature = (MethodSignature) jp.getSignature();
        String methodName = signature.getName();
        //获取方法上的实际参数
        Object[] args = jp.getArgs();

        //获取方法返回值类型
        Class returnType = signature.getReturnType();

        //获取方法参数类型
        Class[] parameterTypes = signature.getParameterTypes();

        System.out.println(className);
        System.out.println(methodName);
        System.out.println(Arrays.asList(args));
        System.out.println(returnType);
        System.out.println(Arrays.asList(parameterTypes));
    }
}
